package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.qf.mapper.DtsGoodsSpecificationMapper;
import com.qf.pojo.DtsGoodsProduct;
import com.qf.pojo.DtsGoodsSpecification;
import com.qf.service.DtsGoodsSpecificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class DtsGoodsSpecificationServiceImpl implements DtsGoodsSpecificationService {
    @Autowired
    DtsGoodsSpecificationMapper specificationMapper;

    @Override
    public void updateSpecification(Integer id, DtsGoodsSpecification[] specifications) {

        LambdaQueryWrapper<DtsGoodsSpecification> qw = new LambdaQueryWrapper<>();
        qw.eq(DtsGoodsSpecification::getGoodsId,id);
        specificationMapper.delete(qw);

        if(specifications!=null&&specifications.length>0){
            for (DtsGoodsSpecification specification : specifications) {
                specification.setAddTime(new Date());
                specification.setUpdateTime(new Date());
                specification.setGoodsId(id);
                specificationMapper.insert(specification);
            }
        }
    }

    @Override
    public void deleteById(Integer goodsId) {
        DtsGoodsSpecification specification = new DtsGoodsSpecification();
        specification.setDeleted(true);
        LambdaQueryWrapper<DtsGoodsSpecification> qw = new LambdaQueryWrapper();
        qw.eq(DtsGoodsSpecification::getGoodsId,goodsId);



        specificationMapper.update(specification,qw);
    }

    @Override
    public void addspecification(Integer id, DtsGoodsSpecification[] specifications) {
        if(specifications!=null&&specifications.length>0){
            for (DtsGoodsSpecification specification : specifications) {
                specification.setAddTime(new Date());
                specification.setUpdateTime(new Date());
                specification.setGoodsId(id);
                specificationMapper.insert(specification);
            }
        }
    }
}
